package org.lex.collection.tree;

import java.io.PrintWriter;
import java.io.StringWriter;

import org.lex.string.DefaultPrinter;
import org.lex.string.IFormatter;

public class TreeUtils {
	public static final IFormatter<Object> DEFAULT_PRINTER = new DefaultPrinter<Object>();

	public static String print(ITreeNode root) {
		StringWriter sw = new StringWriter();
		PrintWriter pw = new PrintWriter(sw);
		print(root, pw);
		pw.flush();
		return sw.toString();
	}

	public static String print(ITreeNode root, IFormatter<Object> dataPrinter) {
		StringWriter sw = new StringWriter();
		PrintWriter pw = new PrintWriter(sw);
		print(root, dataPrinter, pw);
		pw.flush();
		return sw.toString();
	}

	public static void print(ITreeNode root, PrintWriter out) {
		root.print(TreeNode.DEFAULT_IDENT, TreeNode.DEFAULT_STEP, DEFAULT_PRINTER, out);
	}

	public static void print(ITreeNode root, String ident, PrintWriter out) {
		root.print(ident, TreeNode.DEFAULT_STEP, DEFAULT_PRINTER, out);
	}

	public static void print(ITreeNode root, IFormatter<Object> dataPrinter, PrintWriter out) {
		root.print(TreeNode.DEFAULT_IDENT, TreeNode.DEFAULT_STEP, dataPrinter, out);
	}

	public static void print(ITreeNode root, String ident, IFormatter<Object> dataPrinter, PrintWriter out) {
		root.print(ident, TreeNode.DEFAULT_STEP, dataPrinter, out);
	}
}
